﻿
function GetpageHtml(totalPage, curPage, htmlID)
{
    var PageNum =6;//中间显示的页数
   var sb = "";
    if (totalPage > 1) //总页数>0
    {
       sb+="<label>当前页" + curPage + "/" + totalPage + "总页</label>&nbsp;&nbsp;";
        sb+="<span onclick=\"GoToPage(1,'" + htmlID + "')\">首页</span>";
        var prePage = 0; //上一页
        var nextPage = 0;//下一页
        if (curPage - 1 < 1)
            prePage = 1;
        else
            prePage = curPage - 1;
        if (curPage + 1 > totalPage)
            nextPage = totalPage;
        else
            nextPage = curPage + 1;
        sb+=" <span onclick=\"GoToPage(" + prePage + ",'" + htmlID + "')\">上一页</span>";
        // 1 2 3 4 5 6 7 8
        var css = "one-page2";
        if (totalPage <= PageNum)
        {
            for (var i = 1; i <= totalPage; i++) {
                sb += " <span onclick=\"GoToPage(" + i + ",'" + htmlID + "')\" class=\"one-page1 " + (curPage == i ? css : "") + "\">" + i + "</span>";
            }
        }
        else if (totalPage - curPage < PageNum)
        {
            for (var i = PageNum-1; i >= 0; --i) {
                sb += " <span onclick=\"GoToPage(" + (totalPage - i) + ",'" + htmlID + "')\" class=\"one-page1 " + ((totalPage - i) == curPage ? css : "") + "\">" + (totalPage - i) + "</span>";
            }
        }
        else
        {
            if (curPage <= PageNum)
            {
                for (var i = 1; i <= PageNum; i++) {
                    sb += " <span onclick=\"GoToPage(" + i + ",'" + htmlID + "')\" class=\"one-page1 " + (curPage == i ? css : "") + "\">" + i + "</span>";
                }
            }
            else
            {
                var partNum = parseInt(PageNum / 2)
                for (var i = -partNum ; i <= partNum; i++) {
                    sb += " <span onclick=\"GoToPage(" + (curPage + i) + ",'" + htmlID + "')\" class=\"one-page1 " + (i == 0 ? css : "") + "\">" + (curPage + i) + "</span>";
                }
            }
        }
        sb+=" <span onclick=\"GoToPage(" + nextPage + ",'" + htmlID + "')\">下一页</span>";
        sb+=" <span onclick=\"GoToPage(" + totalPage + ",'" + htmlID + "')\">尾页</span>";
    }
    $("#" + htmlID).html(sb);
}